home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 5
/
Aminet 5 - March 1995.iso
/
Aminet
/
misc
/
amag
/
AM9410_2.lha
/
Tips & Tricks
/
ShellTools
/
Pipe.doc
< prev
next >
Wrap
Text File
|
1992-06-13
|
3KB
|
91 lines
Pipe
Template: COMMAND/A/F
The PIPE command is like the RUN command, with several differences. The PIPE
command is designed to run several commands at a time, redirecting the output of
one into the input of the next.
The PIPE command can also be used to run multiple commands; but its main use is
for the piping.
Commands are separated by the vertical bar character (|) for a pipe operation, ie
pipe list sys: | more
NOTE: use of redirection in commands will prevent the proper transfer of output
from one command to the next.
All the commands in the PIPE command line are run asynchronously, except
the last one; synchronization is provided by the blocking pipes provided
by the queue-handler.
The pipe command works best with commands that will look to standard input for
input, and send output to standard output. Unfortunately, many Amiga programs do
not do this; instead they demand an input file (and sometimes even an output file)
Rather than just not work with those commands, the PIPE command supplies two fake
file handles, similar to the NIL: file handle, called IN: and OUT:, representing
the data from the preceeding command and the output to the next command. Thus it
becomes possible to use commands like:
pipe list | sort in: out: | more
or
pipe list #?.c lformat="rlog %n" | execute in:
It is often convienent to define an alias for commands that you use
frequently with pipes that require in: and out:, ie
alias psort sort in: out:
will allow you to do things like:
pipe list lformat=%n | psort | more
You can even do things like:
alias plist pipe list lformat=%n | psort | more
Now you have an alias that does a sorted list through the more command.
To use The PIPE command for multiple commands, the individual commands are
seperated by the \ rather than the |. Output is not passed from one stage
to the next. In the current implementation, each command is run in
a seperate subshell; this is subject to change in a future revision.
The PIPE command allows you to change the pipe (and multiple command)
characters. PIPE looks at the shell variables __pchar and __mchar
(note the 2 underscores) for pipe character and multiple character.
You can use any one or two character combination, ie
set __pchar ||
will set your pipe character(s) to two vertical bars.
Pipe is best used as a resident command.
Note: If you put a RUN in a PIPE command line you probably won't get
quite what you expect, as all the commands are already being
run in the background.
If you control-C out of a PIPE operation, (or if there is some other
problem like a mistyped command) you will see the message "broken pipe",
and the pipe will drain; if the commands have produced a lot of output,
this may take a few seconds, as the current implementation of the queue-handler
does not support a 'flush pipe' operation.
Also, only the last command in the pipe receives the control-C.
(Originally, pipe sent a control-C to every command in the pipe; some
commands got upset) If you need to, you can find the other commands
by using the status command, and can issue them a BREAK manually.